﻿@{
    ViewBag.Title = "用户组列表";
    Layout = "~/Views/Shared/_LayoutList.cshtml";
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户组列表</title>
</head>
<link rel="stylesheet" href="../../admin/css/other/person.css" />
<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">用户组名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="user-table" lay-filter="user-table"></table>
        </div>
    </div>

    <script type="text/html" id="user-toolbar">
        @{
            //验证是否有管理员权限
            if ((ViewBag.Role as List<string>).Count(s => s.Contains("3")) > 0)
            {
               <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
                    <i class="layui-icon layui-icon-delete"></i>
                    删除
                </button>
            }
        }

    </script>

    <script type="text/html" id="user-bar">
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
        @{
            //验证是否有管理员权限
            if ((ViewBag.Role as List<string>).Count(s => s.Contains("3")) > 0)
            {
               <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>

            }
        }



    </script>
    <script>
        layui.use(['table', 'form', 'jquery','common'], function() {
            let table = layui.table;
            let form = layui.form;
            let $ = layui.jquery;
            let common = layui.common;
                    let laydate = layui.laydate;
                   //日期时间范围
        laydate.render({
          elem: '#beginTime'
          ,type: 'datetime'
          ,range: false
        });
                //日期时间范围
        laydate.render({
          elem: '#endTime'
          ,type: 'datetime'
          ,range: false
        });

            let cols = [
                [{
                        type: 'checkbox'
                    },
                    {
                        title: 'Id',
                        field: 'Id',
                        align: 'center'
                    },
                    {
                        title: '用户组名称',
                        field: 'GroupName',
                        align: 'center'
                    },
                    {
                        title: '创建时间',
                        field: 'CreateTime',
                        align: 'center',
                        templet: '#user-createTime'
                    },
                    {
                        title: '最后修改时间',
                        field: 'LastModifyTime',
                        align: 'center',
                        templet: '#user-createTime'
                    },
                    {
                        title: '操作',
                        toolbar: '#user-bar',
                        align: 'center',
                        width: 150
                    }
                ]
            ]

            table.render({
                elem: '#user-table',
                url: 'GetPageList',
                page: true,
                cols: cols,
                skin: 'line',
                toolbar: '#user-toolbar',
                 response: {
                statusName: 'Code' //规定数据状态的字段名称，默认：code
                , statusCode: 200 //规定成功的状态码，默认：0
                , msgName: 'Msg' //规定状态信息的字段名称，默认：msg
                , countName: 'recordCount' //规定数据总数的字段名称，默认：count
                , dataName: 'ResData' //规定数据列表的字段名称，默认：data
            },
                defaultToolbar: [{
                    title: '刷新',
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter', 'print', 'exports']
            });

            table.on('tool(user-table)', function(obj) {
                if (obj.event === 'remove') {
                    window.remove(obj);
                } else if (obj.event === 'edit') {
                    window.edit(obj);
                }
            });

            table.on('toolbar(user-table)', function(obj) {
            if (obj.event === 'refresh') {
                    window.refresh();
                } else if (obj.event === 'batchRemove') {
                    window.batchRemove(obj);
                }
            });

            form.on('submit(user-query)', function(data) {
                table.reload('user-table', {
                    where: data.field
                })
                return false;
            });


            window.edit = function(obj) {
                layer.open({
                    type: 2,
                    title: '查看详情',
                    shade: 0.1,
                   area: ['100%','100%'],
                    content: 'Update?userId='+obj.data.Id
                });
            }

            /**
             * 批量删除
             */
            window.batchRemove = function(obj) {

                var checkIds = common.checkField(obj,'Id');

                if (checkIds === "") {
                    layer.msg("未选中数据", {
                        icon: 3,
                        time: 1000
                    });
                    return false;
                }

                layer.confirm('确定要删除这些用户组吗', {
                    icon: 3,
                    title: '提示'
                }, function(index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: "BatchDelete?Ids=" + checkIds,
                        dataType: 'json',
                        type: 'post',
                        success: function(result) {
                            layer.close(loading);
                            if (result.Code == 200) {
                                layer.msg(result.Msg, {
                                    icon: 1,
                                    time: 1000
                                }, function() {
                                    table.reload('user-table');
                                });
                            } else {
                                layer.msg(result.Msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                });
            }

            window.refresh = function(param) {
                table.reload('user-table');
            }
        })
    </script>
</body>
</html>
